(function($) {

	/**
	 * 扩展功能
	 */
	$.validator.addMethod("alphanumeric", function(value, element) {
		return this.optional(element) || /^\w+$/i.test(value);
	}, "只能输入字母，数字或下划线");
	
	$.validator.addMethod("lettersonly", function(value, element) {
		return this.optional(element) || /^[a-z]+$/i.test(value);
	}, "只能输入字母"); 
	
	$.validator.addMethod("phone", function(v, element) {
	    v = v.replace(/\s+/g, ""); 
		return this.optional(element) || v.match(/^[0-9 \(\)]{7,30}$/);
	}, "输入的手机号不符合规则");
	
	$.validator.addMethod("postcode", function(v, element) {
	    v = v.replace(/\s+/g, ""); 
		return this.optional(element) || v.match(/^[0-9 A-Za-z]{5,20}$/);
	}, "输入的邮政编码不符合规则");
	
	$.validator.addMethod("date", function(v, element) {
	    v = v.replace(/\s+/g, ""); 
		return this.optional(element) || v.match(/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/);
	});

	$.validator.addClassRules({
		date: {date: false},
		alphanumeric: { alphanumeric: true },
		lettersonly: { lettersonly: true },
		phone: { phone: true },
		postcode: {postcode: true}
	});
	
	$.validator.setDefaults({
		errorElement : "span",
		errorPlacement: function(error, element) {
			var wrap = $("<span class='jdmer_validate_error'></span>");
			wrap.html(error);
		    if(element.hasClass("jdmer_form_element_target")){
		    	wrap.insertAfter(element.parents(".jdmer_form_element").eq(0));
		    }else{
		    	wrap.insertAfter(element);
		    }
		}
	});
	
	if($.metadata){
		$.metadata.setType("attr", "validate");
	}
	
	

})(jQuery);